package com.migu.rbac.service;

import com.migu.rbac.repository.SysRoleMenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 15:13 2019/4/3
 * @Version 1.0
 **/
@Service
@Transactional
public class SysRoleMenuService {

    @Autowired
    SysRoleMenuRepository roleMenuRepository;


    //分配角色前先删除原有权限信息
    public boolean updateRoleMenu(int roleid, int[] menus) {
        roleMenuRepository.deleteRoleMenu(roleid);
        if (menus.length == 0) {
            return false;
        }
        roleMenuRepository.saveRoleMenu(roleid, menus);
        return true;
    }

    //查询角色下拥有的菜单id
    public int[] selectMenuByRoleId(int roleid) {
        return roleMenuRepository.selectMenuByRoleId(roleid);
    }


}
